how nested for loop works with animation